<?php
/**
 * Filtering, Formating, Validating, Parsing and modeling statements SQL.
 * Assume MySQL platforme and Standard SQL language
 * @see http://pear.php.net/package/SQL_Parser
 * @labels zend, Sql, structure, php, MySQL, Parser
 */
class Zend_Sql
{
	/**
	 * @var Zend_Db_Adapter_Abstract
	 */
	static protected $defaultAdapter;
	
	/**
	 * @var Zend_Sql_Adapter_Abstract
	 */
	protected $adapter;

	/**
	 * @return the $defaultAdapter
	 */
	public static function getDefaultAdapter() {
		// @TODO lazyLoad
		//if (!isset(self::$defaultAdapter)) {
		//	self::$defaultAdapter = 'Standard';
		//}
		return self::$defaultAdapter;
	}

	/**
	 * @return the $adapter
	 */
	public function getAdapter() {
		if (!isset($this->adapter)) {
			$this->adapter = self::getDefaultAdapter();
		}
		return $this->adapter;
	}

	/**
	 * @param Zend_Sql_Adapter_Abstract $defaultAdapter
	 */
	public static function setDefaultAdapter($defaultAdapter) {
		self::$defaultAdapter = $defaultAdapter;
	}

	/**
	 * @param Zend_Sql_Adapter_Abstract $adapter
	 */
	public function setAdapter($adapter) {
		$this->adapter = $adapter;
	}

	/**
	 * @param String|Array $spec
	 * @param Null|Array $options
	 */
	public function __construct($spec, $options=null) {
		// shemat
		$this->setOptions($options);
	}
	
	/**
	 * @param String $sql
	 * @return Array<Zend_Sql_Abstract>
	 */
	static public function parse($sql) {
		$sql = new Zend_Sql_Adapter_MySql('db', 'test');
		return $sql->parse($sql);
	}
	
	/**
	 * @param String $sql
	 * @return Array<Zend_Sql_Abstract>
	 */
	static public function factory($adapter='Standard') {
		
		$sql = new Zend_Sql_Adapter_MySql();
		return $sql->parse($sql);
	}
	
	
	
	
	
	
	/* Data Manipulation Language */
	/**
	 * @return Zend_Sql_Statement_Select
	 */
	public function select() {
		//Zend_Sql::setDefaultAdapter($this->adapter);
		Zend_Sql_Statement::factory('select');
		 
		$lexer = 'Zend_Sql_Adapter_' . $type . '_Statement_Select';
		try {
			Zend_Loader::loadClass($lexer, array(
				'Zend_Sql_Adapter_' . $type . '_Statement_Select',
				'Zend_Sql_Adapter_Standard_Statement_Select',
			));
			$lexer = new $lexer(array('lookahead'=>3, 'allowIdentFirstDigit'=>true));
		} catch (Zend_Exception $e) {
			require_once 'Zend/Db/Sql/Exception.php';
			throw new Zend_Sql_Exception('No such File or Class lexer :"'.$type.'"');
			$lexer = 'Zend_Sql_Adapter_Standard_Statement_Select';
		}

		if (is_null($lexer)) {
		} // else autoload ?
		 
		//Zend_Sql::setDefaultAdapter('MySql');
		//$sql = new Zend_Sql($db);
		//$sql->select();
		$statement = Zend_Sql::factory('select', 'statement');
		$statement = Zend_Sql_Statement::factory('select');
		return null;
	}
	/**
	 * @return Zend_Sql_Statement_Insert
	 */
	public function insert() { }
	/**
	 * @return Zend_Sql_Statement_Update
	 */
	public function update() { }
	/**
	 * @return Zend_Sql_Statement_Delete
	 */
	public function delete() { }

	/* Data Definition Language */
	public function createView() {
		 
	}
	public function createTable() {
		 
	}
	/* Data Control Language */
	public function alterTable() {
		 
	}
	/* Transaction Control Language */
}
